package com.hsgene.user.controller;

import com.hsgene.common.util.resolver.FromSession;
import com.hsgene.common.util.result.ApiResult;
import com.hsgene.common.util.web.session.UserInfo;
import com.hsgene.user.constants.UserIntType;
import com.hsgene.user.dto.user.GeneticTestingUserDto;
import com.hsgene.user.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 获取用户信息
 *
 * @author wangbing
 * @version 1.0, 2018/10/17
 */
@RestController
@RequestMapping("/v1.0/genetic/testing/user")
public class GeneticUserController {

    @Resource
    private UserService userService;

    /**
     * 获取用户信息
     *
     * @param userInfo 用户信息
     * @return 用户信息
     */
    @GetMapping("")
    public ApiResult<GeneticTestingUserDto> getCurrentUserInfo(@FromSession UserInfo userInfo) {
        UserIntType userIntType = UserIntType.getEnum(userInfo.getUserType());
        return userService.findByUserId(userInfo.getUserId(), userIntType);
    }

    /**
     * 获取用户信息
     *
     * @param userId 用户id
     * @return 用户信息
     */
    @GetMapping("{userId}")
    public ApiResult<GeneticTestingUserDto> getUserInfo(
            @PathVariable("userId") String userId) {
        return userService.findByUserId(userId, null);
    }
}
